// the brothers problem
// ml:ccf += -pthread
// ml:ldf += -pthread
#include <iostream>
#include <vector>
#include <thread>
#include <random>
#include <mutex>

std::vector<int> counts{100, 200, 300, 400};

int main()
{
    int a{}, b{};

    std::mutex m;
    std::vector<std::thread> threads;
    for (auto count : counts)
        threads.emplace_back([count, &a, &b, &m]() mutable {
            std::random_device rd;
            std::mt19937 gen{rd()};
            std::uniform_int_distribution<> dis{1, 10000};
            while (count--) {
                auto x = dis(gen);
                std::lock_guard<std::mutex> g{m};
                a += x;
                b -= x;
            }
        });
    for (auto & thread : threads)
        if (thread.joinable()) thread.join();
    std::cerr << "\e[31m" << a << " + \e[32m" << b << "\e[0m = " << a + b << "\n";
}

